<div id="required_fields_message"><?php echo lang('common_fields_required_message'); ?></div>
<ul id="error_message_box"></ul>
<?php
if(!empty($service_info)){
	foreach($service_info as $k=>$v){
		$cus_id = $v['customer_id'];
		$customer_name=$v['customer_name'];
		$phone_num=$v['phone_num'];
		$cus_address = $v['cus_address'];
		$product_brand=$v['product_brand'];
		$quantity=$v['quantity'];
		$product_model=$v['product_model'];
		$service_note=$v['service_note'];
		$problem_description=$v['problem_description'];
		$service_cost=$v['service_cost'];
		$services_status=$v['services_status'];
		$date_return = $v['date_return'];
		$s_date = $v['date_created'];
	}
}else{
	$customer_name  = $this->session->userdata('customer_name');
	$phone_num  = $this->session->userdata('phone_num');
	
}
echo form_open('services/save/'.$v['service_id'],array('id'=>'item_form'));
?>
<fieldset id="item_basic_info">
	<legend><?php echo lang("service_basic_information"); ?></legend>
		<div class="field_row clearfix">
		<?php echo form_label(lang('name_of_customer').':', 'name_of_customer',array('class'=>'wide')); ?>
			<div class='form_field'>
			<?php echo form_input(array(
				'name'=>'customer_name',
				'id'=>'customer_name',
				'value'=>$customer_name)
			);?>
			</div>
		</div>
		
		<div class="field_row clearfix">
		<?php echo form_label(lang('customer_phone').':', 'phone',array('class'=>'required wide')); ?>
			<div class='form_field'>
			<?php echo form_input(array(
				'name'=>'phone_num',
				'id'=>'phone_num',
				'value'=>$phone_num)
			);?>
			</div>
		</div>
		
		<div class="field_row clearfix">
		<?php echo form_label(lang('product_brand').':', 'brand',array('class'=>'required wide')); ?>
			<div class='form_field'>
			<?php echo form_input(array(
				'name'=>'product_brand',
				'id'=>'product_brand',
				'value'=>$product_brand)
			);?>
			</div>
		</div>
		
		<div class="field_row clearfix">
		<?php echo form_label(lang('product_model').':', 'model',array('class'=>'required wide')); ?>
			<div class='form_field'>
			<?php echo form_input(array(
				'name'=>'product_model',
				'id'=>'product_model',
				'value'=>$product_model)
			);?>
			</div>
		</div>
				
		<div class="field_row clearfix">
		<?php echo form_label(lang('serv_note').':', 'note',array('class'=>'wide')); ?>
			<div class='form_field'>
			<?php echo form_textarea(array(
				'name'=>'product_note',
				'id'=>'product_note',
				'value'=>$service_note,
				'rows'=>'5',
				'cols'=>'17')
			);?>
			</div>
		</div>
		
		<div class="field_row clearfix">	
		<?php echo form_label(lang('problem').':', 'problem',array('class'=>'required wide'));  ?>
			<div class='form_field'>
				<select name="product_problem">
				<?php 
					foreach($service_problem as $problem){
						if(!empty($problem)){
							list($key,$value) = explode(":", $problem);
				?>
							<option value="<?php echo $value;?>" <?php if($problem_description == $value){ echo "selected='selected'" ; }?>><?php echo $key; ?></option>
				<?php 			
						}
					}
				?>
				</select>
			</div>
		</div>
		<div class="field_row clearfix">
		<?php echo form_label(lang('product_cost').':', 'cost',array('class'=>'required wide')); ?>
			<div class='form_field'>
			<?php echo form_input(array(
				'name'=>'product_cost',
				'id'=>'product_cost',
				'value'=>$service_cost)
			);?>
			</div>
		</div>
                <?php
                    $date = explode('-',$date_return); 
                    $date_return =  $date[2].'-'.$date[1].'-'.$date[0];
                ?>
		<div class="field_row clearfix">
		<?php echo form_label(lang('product_date_return').':', 'date_return',array('class'=>'required wide')); ?>
			<div class='form_field'>
			<?php echo form_input(array(
				'name'=>'product_date_return',
				'id'=>'product_date_return',
				'value'=> $date_return)
			);?>
			</div>
		</div>
		<?php if(!empty($list_items_add)){?>
		<div class="field_row clearfix">
			<div class='form_field'>
			<?php 
				echo "<p> Items added : </p>";
					foreach($list_items_add as $l_i_a){
						$key = $l_i_a['name'];
						if(!empty($key)){
							echo "<p>";
							echo form_checkbox(array(
						    'name'        => $l_i_a['id'],
						    'value'       => $l_i_a['name'],
						    'checked'     => TRUE
						    ));
						    echo " ".$l_i_a['name'];
						    echo "</p>";
						}				
					}
		    ?>
			</div>
		</div>
		<?php }?>
		
		<input type="hidden" name='customer' value="<?php echo $customer_id ;?>" />
		<input type="hidden" value="<?php if(!empty($s_date)){ echo $s_date ;}?>" readonly="readonly" name="date">
		<?php
		echo form_submit(array(
			'name'=>'submit',
			'id'=>'submit',
			'value'=>lang('common_submit'),
			'class'=>'submit_button float_right')
		);
	?>
</fieldset>
<?php
echo form_close();
?>
<script type='text/javascript'>
$(document).ready(function()
{
	$('#item_form').validate({
		submitHandler:function(form)
		{
			$(form).ajaxSubmit({
			success:function(response)
			{
				tb_remove();
				post_service_form_submit(response);
			},
			dataType:'json'
		});

		},
		errorLabelContainer: "#error_message_box",
 		wrapper: "li",
		rules:
		{
			phone_num:{
				required:true,
				number:true
			},
			product_brand:"required",
			product_model:"required",
			product_cost:
			{
				required:true,
				number:true
			}
   		},
		messages:
		{
			phone_num:
			{
				required:"<?php echo lang('phone_required'); ?>",
				number:"<?php echo lang('phone_number'); ?>"
			},
			cus_address:"<?php echo lang('cus_address_required'); ?>",
			product_brand:"<?php echo lang('brand_required'); ?>",
			quantity:
			{
				required:"<?php echo lang('qty_required'); ?>",
				number:"<?php echo lang('qty_number'); ?>"
			},
			product_model:"<?php echo lang('model_required'); ?>",
			product_cost:
			{
				required:"<?php echo lang('cost_required'); ?>",
				number:"<?php echo lang('cost_number'); ?>"
			}
		}
	});
	Date.format = 'dd-mm-yyyy';
	$(function(){
		$('#product_date_return').datePicker({clickInput:true});
	});
});
</script>